﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Web.Mvc;
using BoC.Web.Mvc.PrecompiledViews;

namespace MvcTemplates
{
    public class Templates
    {
        public static void Configure( string rootVirtualPath = null )
        {
            DefaultProfile = new Templates();

            if ( string.IsNullOrEmpty( rootVirtualPath ) )
            {
                ApplicationPartRegistry.Register( Assembly.GetExecutingAssembly() );    
            }
            else
            {
                ApplicationPartRegistry.Register( Assembly.GetExecutingAssembly(), rootVirtualPath );
            }            
        }

        private static string DefaultProfileName = "MvcTemplates.DefaultProfile";
        
        public static Templates DefaultProfile
        {
            get { return Profiles[DefaultProfileName]; }
            set { Profiles[DefaultProfileName] = value; }
        }

        public static Dictionary<string, Templates> Profiles = new Dictionary<string, Templates>();        
        
        private CloneableTagBuilder _labelContainer;
        private CloneableTagBuilder _fieldContainer;
        private CloneableTagBuilder _checkBoxListCheckBoxContainer;
        private CloneableTagBuilder _radioButtonListRadioButtonContainer;
        private CloneableTagBuilder _requiredTagBuilder;
        private CloneableTagBuilder _clearFix;
        private CloneableTagBuilder _helpMessage;

        public CloneableTagBuilder LabelContainer
            {
                get
                {
                    if ( _labelContainer == null )
                    {
                        _labelContainer = new CloneableTagBuilder( "div" );
                        _labelContainer.AddCssClass( "editor-label" );
                    }
                    return _labelContainer;
                }
                set { _labelContainer = value; }
            }
        public CloneableTagBuilder FieldContainer
            {
                get
                {
                    if ( _fieldContainer == null )
                    {
                        _fieldContainer = new CloneableTagBuilder( "div" );
                        _fieldContainer.AddCssClass( "editor-field" );
                    }
                    return _fieldContainer;
                }
                set { _fieldContainer = value; }
            }
        public CloneableTagBuilder CheckBoxListCheckBoxContainer
            {
                get
                {
                    if ( _checkBoxListCheckBoxContainer == null )
                    {
                        _checkBoxListCheckBoxContainer = new CloneableTagBuilder( "span" );
                        _checkBoxListCheckBoxContainer.AddCssClass( "check-box-list-check-box-container" );
                    }

                    return _checkBoxListCheckBoxContainer;
                }
                set { _checkBoxListCheckBoxContainer = value; }
            }
        public CloneableTagBuilder RadioButtonListRadioButtonContainer
            {
                get
                {
                    if ( _radioButtonListRadioButtonContainer == null )
                    {
                        _radioButtonListRadioButtonContainer = new CloneableTagBuilder( "span" );
                        _radioButtonListRadioButtonContainer.AddCssClass( "radio-button-list-radio-button-container" );
                    }

                    return _radioButtonListRadioButtonContainer;
                }
                set { _radioButtonListRadioButtonContainer = value; }
            }
        public CloneableTagBuilder RequiredTagBuilder
            {
                get
                {
                    if ( _requiredTagBuilder == null )
                    {
                        _requiredTagBuilder = new CloneableTagBuilder( "span" );
                        _requiredTagBuilder.AddCssClass( "required" );
                        _requiredTagBuilder.InnerHtml = "*";
                    }

                    return _requiredTagBuilder;
                }
                set { _requiredTagBuilder = value; }
            }
        public CloneableTagBuilder ClearFix
            {
                get
                {
                    if ( _clearFix == null )
                    {
                        _clearFix = new CloneableTagBuilder( "span" );
                        _clearFix.AddCssClass( "clear-fix" );     
                    }
                    return _clearFix;
                }
                set { _clearFix = value; }
            }
        public CloneableTagBuilder HelpMessage
            {
                get
                {
                    if ( _helpMessage == null )
                    {
                        _helpMessage = new CloneableTagBuilder( "span" );
                        _helpMessage.AddCssClass( "help-message" );
                    }

                    return _helpMessage;
                }
                set { _helpMessage = value; }
            }
        
        public Func<ViewContext, string> DefaultValidationMessage = x => "*";
        
        public string SingleLineTextBoxClasses = "text-box single-line";
        public string MultiLineTextBoxClasses = "text-box multi-line";
        public string CheckBoxClasses = "check-box";
        public string AutoCompleteClasses = "text-box single-line autocomplete";            
        public string CheckBoxListClasses = "check-box check-box-list";
        public string DateTimeClasses = "text-box single-line datetime";
        public string DecimalClasses = "text-box single-line";
        public string DropDownClasses = "drop-down-list";
        public string PasswordClasses = "text-box single-line password";
        public string RadioButtonListClasses = "radio-button radio-button-list";            
               
    }
}